elisaveterafandomcom-20200214-history
Community Central Blogs/The If and the Switch
So some of you may have seen the or . Well, have no fear, because there is almost always a solution to the problem! This blog will hopefully have you coding with the #if and the #switch by the time you're done reading! The Code Here below, I have a selection of coding from a wiki for a TV show, the coding will be understandable to some users, which is a good thing! For those of you who have absolutely no clue what all this does, don't worry, I'm going to break it down bit by bit, and show you which piece I'm talking about as I break it down. c: Lets get started! }| style="width:50%; padding-left:15px; border-radius:5px; background-color:#3366CC; color:#f2f2f2; font-size:100%;" Seasons: } |season1 = Season 1 Characters Characters |season1-2 = Season 1 Characters Characters Season 2 Characters Characters |season2 = Season 2 Characters Characters |season2-3 = Season 2 Characters Characters Season 3 Characters Characters |season1-2-3 = Season 1 Characters Characters Season 2 Characters Characters Season 3 Characters Characters |#default = } }} |}} Breaking down the If Okay so first of all we have the following code: }| Now, to call up an #if, we have to use two "{'''" brackets, just like when we call up any other template. (Make sure you close it with two "}" brackets before you publish your work! Otherwise your coding won't work.) Now the } is what the #if statement is looking for. The } means that if you don't enter something into the seasons field, you don't see } in your published template. Now, an #if statement looking for something? What, simple, all the #if is doing, is checking to see if we put |seasons= my season is on fire! in our template! "Why would it do that?" you might ask. Well, this is so that we can hide certain information rows on a template! This is useful if you don't always want the row for a character's season listing to show up. This way, only the information that is entered, shows up on the template. This also means, that if a character doesn't have a large seasonal role in the TV show, you can leave leave |seasons= out of the template entirely! To put this into better perspective, say I've made a page for Shawn Spencer, Psychic Detective. In his infobox, with our nifty coding, when I put in |seasons=my season is on fire! it puts the text, "my season is on fire" in the template when we hit publish. Now if we had left it blank, the row with the information for seasons won't even show up when we hit publish! The Styling style="width:50%; padding-left:15px; border-radius:5px; background-color:#3366CC; color:#f2f2f2; font-size:100%;" '''Seasons: This gives us the following row, I've also added a border and width to the infobox, so that it looks shapely: Now if we add } to our row style, we get the field. Now if we had put }, It would have looked like this: }} |} Now Presenting Switches! Now some of you may be like, "ZOMG! What do I do with all the stuff in the ". Well, that's quite simple! In fact, it's awesome how simple and cool this nifty trick is. That being said, here's the code from our TV show template: } |season1 = Season 1 Characters Characters |season1-2 = Season 1 Characters Characters Season 2 Characters Characters |season2 = Season 2 Characters Characters |season2-3 = Season 2 Characters Characters Season 3 Characters Characters |season1-2-3 = Season 1 Characters Characters Season 2 Characters Characters Season 3 Characters Characters |#default = } }} Okay so first what we want to do, is look at the } what this does, is it see if we put something like, "fire" into the template when we use it on a article page. If the template sees that we put |seasons=fire What it will do, is put "This season is on fire!" into the template when we hit publish. This saves a lot of typing, and can be a nifty trick for helping you categorize items, characters, episodes, and whatever else you can think of! Here's how I have my TV show character template set up: after the } I have: |season1 = it's better on dvd..., |season1-2 = oh season one and two, shazzam!, |season2 = haha season two was great!, |season2-3= twas a sad ending, |season1-2-3= We're going to be here for a while Each "part after the ='s sign" is what will be entered into the template if I put |seasons= season2 or |seasons= season1-2-3. This means that #switch is great for items that appear in different games in a series, or different characters that appear in different seasons, and so on and so forth! Now, you might say, "Slay you've left off that last little bit of the coding!" Well, that's great observation, because this part helps us out greatly! |#default = } }} Okay so, this part functions like a default, almost like a normal setting. |#default = tells the template what to make the seasons row be if we don't put anything into |seasons= via: }. The best part about the default, is that the coding that we have has a } which means that the } won't show up if we don't enter any text. UPDATE Okay, Rofl asked an awesome question! "Does #switch: need #if:?" The answer is..... *Drumroll* #switch does not need #if to work! In this blog, the way the main coding is set up is so that if you don't put anything for } it doesn't even bring up the row! Here's what the code would look like without the #if: style="width:50%; padding-left:15px; border-radius:5px; background-color:#3366CC; color:#f2f2f2; font-size:100%;" Seasons: } |season1 = Season 1 Characters Characters |season1-2 = Season 1 Characters Characters Season 2 Characters Characters |season2 = Season 2 Characters Characters |season2-3 = Season 2 Characters Characters Season 3 Characters Characters |season1-2-3 = Season 1 Characters Characters Season 2 Characters Characters Season 3 Characters Characters |#default = } }} Now with this coding, the seasons row will show up no matter what. However, the snippet right here: |#default = } }} makes it so that } doesn't show up when we click publish on the template... }} }} |} If we remove that little | then the } will show up.